﻿using System.Security.Principal;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Moq;

namespace SweetSurvey.Tests.ControllerTests
{
    /// <summary>
    /// The base class of all controller test classes.
    /// </summary>
    public class ControllerTestBase : TestBase
    {
        /// <summary>
        /// Default user name.
        /// </summary>
        protected string DefaultUserName
        {
            get { return "userName"; }
        }

        /// <summary>
        /// Mock HttpContext
        /// </summary>
        protected Mock<HttpContextBase> MockHttpContext
        {
            get
            {
                var mockHttpContext = new Mock<HttpContextBase>();
                mockHttpContext.Setup(context => context.User)
                    .Returns(new GenericPrincipal(new GenericIdentity(DefaultUserName), null));
                
                return mockHttpContext;
            }
        }

        /// <summary>
        /// Get controller context.
        /// </summary>
        /// <param name="controller">The testing controller.</param>
        /// <returns>The result.</returns>
        protected ControllerContext GetControllerContext(ControllerBase controller)
        {
            return new ControllerContext(
                new RequestContext(MockHttpContext.Object, new RouteData()), controller);
        }
    }
}
